package Homework13;

public class Test {
    public static void main(String[] args) {
        Teacher teacher = new Teacher("张飞", 30, '男', 5);
        teacher.printInfo();
        System.out.println("-----------------------------");
        Student student = new Student("小明", 15, '男', "00023102");
        student.printInfo();

        //多态数组
        Person[] p = new Person[4];
        p[0] = new Student("张三", 10, '男', "123456");
        p[1] = new Student("李四", 15, '男', "234567");
        p[2] = new Teacher("mary" , 25, '女', 2);
        p[3] = new Teacher("tom", 30, '男', 15);

        Test test = new Test();
        test.arraySort(p);
        for(int i = 0; i < p.length; i++){
            p[i].printInfo();
        }
    }
    public void arraySort(Person[] p){
        //冒泡排序，每轮找到最大的一个数
        Person temp = null;
        for(int i = 0; i < p.length - i; i++){
            for(int j = 0; j < p.length - i - 1; j++){
                if(p[j].getAge() < p[j + 1].getAge()){
                    temp = p[j];
                    p[j] = p[j + 1];
                    p[j + 1] = temp;
                }
            }
        }
    }
}
